﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MdcService.Configuration;
using MdcService.DataAccess;
using MdcService.External;
using MdcService.Log;
using MdcService.Structure;
using MdcService.Structure.Enum;

namespace MdcService.Service
{
    public class HistoryDbService:IService
    {
        private IDataAccess<MachineValue> _historyDataAccess;
        private ConfigurationService _configurations;
        private RunningContext _runningContext;
        private ILogging _logging;

        public event EventHandler<EventArgs> Started;
        public event EventHandler<EventArgs> Stopped;

        public HistoryDbService(IHistoryDataAccess<MachineValue> historyDataAccess, ConfigurationService configurations, RunningContext runningContext, ILogging logging)
        {
            _historyDataAccess = historyDataAccess;
            _configurations = configurations;
            _runningContext = runningContext;
            _logging = logging;

        }


        public void Start()
        {
            if (_runningContext.HistoryDataServiceState == ServiceState.Running) return;

            _runningContext.HistoryDataServiceState = ServiceState.Running;
            Started?.Invoke(this,new EventArgs());
        }

        public void Stop()
        {
            if (_runningContext.HistoryDataServiceState == ServiceState.Stopped) return;
            _runningContext.HistoryDataServiceState = ServiceState.Stopped;
            Stopped?.Invoke(this,new EventArgs());
        }

 

        public void Insert(MachineValue value)
        {
            _historyDataAccess.Insert(value);
        }

        public void Insert(IEnumerable<MachineValue> values)
        {
            _historyDataAccess.Insert(values);
        }

        public List<MachineValue> Select(string command)
        {
            return _historyDataAccess.Select(command);
        }

        public void Update(MachineValue machineValue)
        {
            _historyDataAccess.Update(machineValue);
        }

        public void Update(IEnumerable<MachineValue> machineValues)
        {
            _historyDataAccess.Update(machineValues);
        }

        public void Delete(MachineValue value)
        {
            _historyDataAccess.Update(value);
        }

        public void Delete(IEnumerable<MachineValue> values)
        {
            _historyDataAccess.Update(values);
        }
    }
}
